package com.wsoft.hr.pm.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.wsoft.hr.pm.entity.HrPmGradeEntity;
import com.wsoft.hr.pm.query.grade.*;
import com.wsoft.hr.pm.service.IHrPmGradeService;
import com.wsoft.hr.pm.vo.grade.GradeVO;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 考核评级 Controller
 *
 * @Author Z001
 * @Date 2025-03-01 08:35:23
 */
@RestController
@Tag(name = "考核评级")
@RequestMapping("/hr/pm/grade")
public class HrPmGradeController {

    @Resource
    private IHrPmGradeService hrPmGradeService;


    // ################################## 工作台接口  ##################################

    @Operation(summary = "工作台更新-考核评级信息", description = "工作台更新-考核评级信息")
    @PostMapping("/workUpdate")
    public ResponseResult update(@RequestBody @Valid HrPmGradeUpdateQuery query) {
        boolean b =  hrPmGradeService.updateHrPmGrade(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "工作台-分页查询", description = "工作台-分页查询")
    @PostMapping("/workList")
    public ResponseResult workList(@RequestBody @Valid HrPmGradeListQuery query) {
        PageInfo<HrPmGradeEntity> page = hrPmGradeService.workList(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }


    @Operation(summary = "工作台启用-考核评级", description = "工作台启用-考核评级")
    @PostMapping("/workEnable")
    public ResponseResult enable(@RequestBody @Valid HrPmGradeEnableQuery query) {
        boolean b =  hrPmGradeService.enableGrade(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "工作台-获取详情",description = "工作台-获取详情")
    @GetMapping("/workGet")
    public ResponseResult workGet(@RequestParam("id") Long id) {
        HrPmGradeEntity entity = hrPmGradeService.getInfo(id);
        GradeVO convert = Convert.convert(GradeVO.class, entity);
        convert.setHrOrgIds(Convert.toList(Long.class, StrUtil.split(entity.getHrOrgIds(), StrUtil.COMMA)));
        return ResponseResult.success(convert);
    }

    @Operation(summary = "工作台删除",description = "工作台删除")
    @GetMapping("/workDelete")
    public ResponseResult workDelete(@RequestParam("id") Long id) {
        boolean b = hrPmGradeService.workDelete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


    // ################################## 非工作台接口  ##################################

    @Operation(summary = "新增-考核评级", description = "新增-考核评级")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid HrPmGradeInsertQuery query) {
        boolean b =  hrPmGradeService.insertHrPmGrade(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "考核评级-分页查询", description = "考核评级-分页查询")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody @Valid HrPmGradeListQuery query) {
        PageInfo<HrPmGradeEntity> page = hrPmGradeService.listHrPmGrade(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }


    @Operation(summary = "考核评级-详情-列表信息", description = "考核评级-详情-列表信息")
    @PostMapping("/getMemberGrade")
    public ResponseResult getMemberGrade(@RequestBody @Valid HrPmGradeInfoQuery query) {
        return ResponseResult.success(ResponsePage.restPage(hrPmGradeService.getMemberGrade(query)));
    }

    @Operation(summary = "考核评级-详情-统计信息", description = "考核评级-详情-统计信息")
    @GetMapping("/getGradeStatistics")
    public ResponseResult getGradeStatistics(@RequestParam("id") Long id) {
        return ResponseResult.success(hrPmGradeService.getGradeStatistics(id));
    }

    @Operation(summary = "更新-用户考核等级", description = "更新-用户考核等级")
    @PostMapping("/updateMemberGrade")
    public ResponseResult updateMemberGrade(@RequestBody @Valid HrPmMemberGradeUpdateQuery query) {
        boolean b =  hrPmGradeService.updateMemberGrade(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "提交-考核评级", description = "提交-考核评级")
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody @Valid HrPmMemberGradeUpdateQuery query) {
        boolean b =  hrPmGradeService.submit(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除-考核评级",description = "删除-考核评级")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = hrPmGradeService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }





}
